from rest_framework import permissions


class IsAuthor(permissions.BasePermission):
    """
    必须是作者才可以
    """

    def has_permission(self, request, view):
        return request.user.is_superuser or request.user.is_author

    def has_object_permission(self, request, view, obj):
        if request.user.is_superuser:
            return True
        elif request.user == obj.author:
            return True
        else:
            return False


class IsSuperuser(permissions.BasePermission):
    """
    必须是超级用户
    """

    def has_permission(self, request, view):
        return request.user.is_superuser

    def has_object_permission(self, request, view, obj):
        return request.user.is_superuser
